﻿using System;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Streams;

namespace TestApp.Shaders
{
    public  enum ShaderType
    {
        Liquefaction,
    }

    public static class ShaderExtensions
    {
        public static HSVColorPickers.NumberPicker NumberPicker;
        //@Static
        public static Rect GetRect(Vector2 center, float radius, Rect region)
        {
            float diameter = radius + radius;
            Rect rect = new Rect(center.X - radius, center.Y - radius, diameter, diameter);
            rect.Intersect(region);
            return rect;
        }
        public static Rect GetRect(Vector2 a, Vector2 b, float radius)
        {
            float diameter = radius + radius;
            return new Rect(Math.Min(a.X, b.X) - radius, Math.Min(a.Y, b.Y) - radius, Math.Abs(a.X - b.X) + diameter, Math.Abs(a.Y - b.Y) + diameter);
        }

        public static async Task<byte[]> LoadAsync(this ShaderType type)
        {
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(type.GetPath()));
            IBuffer buffer = await FileIO.ReadBufferAsync(file);
            return buffer.ToArray();
        }
        private static string GetPath(this ShaderType type)
        {
            switch (type)
            {
                case ShaderType.Liquefaction: return "ms-appx:///Shaders/Liquefaction.bin";
                default: return null;
            }
        }

    }
}